function disp_list = display_notelist(note_list);

% DISPLAY_NOTELIST - generates a cell array of acquisition strings
%
%    LIST = DISPLAY_NOTELIST(NOTE) generates a cell array LIST of strings
%    for the display of the text comments in the text comment structure
%    NOTE obtained from the subroutine DATAC_NOTEFILE.

% By:   S.C. Molitor (smolitor@med.unc.edu)
% Date: February 18, 2000

% initialize outputs

disp_list = {};

% validate arguments

if (nargin ~= 1)
   msgbox('Invalid number of arguments', 'DISPLAY_NOTELIST Error', 'warn');
   return
elseif (~isstruct(note_list) | isempty(note_list))
   msgbox('LIST must be a structure', 'DISPLAY_NOTELIST Error', 'warn');
   return
end

% find number of digits in largest record for formatting
% determine number of spaces needed for padding

max_rec = max([note_list(:).record]);
num_digits = floor(log10(max_rec)) + 1;
note_fmt = ['%8s [R:%0' int2str(num_digits) 'd] - %s'];
space_fmt = ['%' int2str(num_digits + 15) 's %s'];

% generate cell array of notes
% include record number & time only if different
% otherwise just display note

disp_list{1} = sprintf(note_fmt, note_list(1).time, note_list(1).record, note_list(1).note);
for i = 2 : length(note_list)
   if ((note_list(i).record == note_list(i - 1).record) & ...
         (strcmp(note_list(i).time, note_list(i - 1).time)))
      disp_list{i} = sprintf(space_fmt, ' ', note_list(i).note);
   else
      disp_list{i} = sprintf(note_fmt, note_list(i).time, note_list(i).record, note_list(i).note);
   end
end
return
